package com.monitor.dao;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.monitor.entity.ErpManagement;

/**
 * <p>
 * 检测维护销售维修工作单表 Mapper 接口
 * </p>
 *
 * @author LX
 * @since 2018-09-28
 */
public interface ErpManagementMapper extends BaseMapper<ErpManagement> {
	//工作汇总查询合计
	@Select("${sql}")
	public Map<String, Object> selectTongYong(@Param("sql")String sql);

	//工作汇总查询合计
	@Select("SELECT COUNT(distinct client_name) as allcustomerNum,COUNT(distinct car_number) as allCarNum,COUNT(work_id) as allNum,SUM(purchase) as allPurchase,SUM(sail) as allSail,SUM(erp_repair) as allRepair,SUM(maintian) as allMaintian,SUM(cash) as allCash,SUM(accounts) as allAccounts,SUM(cope) as allCope FROM erp_management WHERE  1=1 ${sql}")
	public Map<String, Object> selectTong(@Param("sql")String sql);
	
	//按客户查询的统计信息
	@Select("SELECT COUNT(distinct client_name) as custallcustomerNum,COUNT(distinct car_number) as custallCarNum,COUNT(work_id) as custallNum,SUM(purchase) as custallPurchase,SUM(sail) as custallSail,SUM(erp_repair) as custallRepair,SUM(maintian) as custallMaintian,SUM(cash) as custallCash,SUM(accounts) as custallAccounts,SUM(cope) as custallCope FROM erp_management WHERE  1=1 AND type=1 and work_place=#{custName} ${sql}")
	public Map<String, Object> selectByWorkPlace(@Param("custName")String custName,@Param("sql")String sql);
	
	//工作汇总 公司名点进去后的合计
	@Select("SELECT COUNT(distinct client_name) as custallcustomerNum,COUNT(distinct car_number) as custallCarNum,COUNT(work_id) as custallNum,COUNT(distinct work_project) as projectNum,count(distinct work_attn) as workAttnNum,COUNT(DISTINCT client_attn) as clientAttnNum,SUM(purchase) as custallPurchase,SUM(sail) as custallSail,SUM(erp_repair) as custallRepair,SUM(maintian) as custallMaintian,SUM(cash) as custallCash,SUM(accounts) as custallAccounts,SUM(cope) as custallCope FROM erp_management WHERE  1=1 AND work_place=#{custName}  ${sql}")
	public Map<String, Object> selectByWorkPlaceDateil(@Param("custName")String custName,@Param("sql")String sql);
	
	//工作汇总 公司名点进去后的客户工作单列表
	@Select("SELECT * FROM erp_management WHERE work_place=#{custName}  ${sql}  ORDER BY dt DESC")
	public List<ErpManagement> selectByWorkPlaceDateilList(@Param("custName")String custName,@Param("sql")String sql);
}
